﻿Imports LinhKienMayTinh.CommonMethods

Public Class NewsDetail
    Inherits BasePage

#Region "Khai báo các event"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim xNews As String = String.Empty

        Dim nNewsPerPage As Integer = 1
        Dim dsNews As DataSet

        Try
            xNews = Me.QueryString("newsdetail")

            dsNews = GetNewsDetail(xNews)
            If dsNews IsNot Nothing AndAlso dsNews.Tables(0).Rows.Count > 0 Then
                ucNewsDetail.DataSource = dsNews
                ucNewsDetail.DataBind()

                Me.Header.Title = Me.AppSettings("SiteName") & " | " & CStr(dsNews.Tables(0).Rows(0)("TITLE"))
            Else
                Context.Items("ErrorCode") = CommonConstants.LINK_NAME_NOT_EXIST
                Server.Transfer("~/Pages/Error.aspx")
            End If
        Catch ex As Exception
            Server.Transfer("~/Pages/Error.aspx")
        End Try
    End Sub

    Private Sub ProductDetail_Init(sender As Object, e As System.EventArgs) Handles Me.Init
        Dim master As LinhKienMayTinhMasterPage = DirectCast(Me.Page.Master, LinhKienMayTinhMasterPage)
        master.CssLinkAdd(ResolveUrl("~/Style/NewsDetailMetroStyle.css"))
    End Sub

#End Region

#Region "Khai báo các function method"

    Protected Function GetNewsDetail(ByVal pNews As String) As DataSet
        Dim xSql As String
        Dim ds As DataSet
        Dim dataAccess As DBAccess

        Try
            dataAccess = New DBAccess(ConfigurationManager.ConnectionStrings("ConStr").ConnectionString)

            xSql = ""
            xSql = xSql & vbCrLf & "SELECT T_NEWS.CODE,"
            xSql = xSql & vbCrLf & "	   T_NEWS.NAME          AS  TITLE,"
            xSql = xSql & vbCrLf & "	   T_NEWS.LINK_NAME,"
            xSql = xSql & vbCrLf & "	   T_NEWS.IMG_LINK,"
            xSql = xSql & vbCrLf & "	   T_NEWS.SUMMARY,"
            xSql = xSql & vbCrLf & "	   T_NEWS.CONTENT,"
            xSql = xSql & vbCrLf & "	   T_NEWS.TAG,"
            xSql = xSql & vbCrLf & "	   T_NEWS.DEL_FLG,"
            xSql = xSql & vbCrLf & "	   T_NEWS.AD_DATE,"
            xSql = xSql & vbCrLf & "	   T_NEWS.UD_DATE"
            xSql = xSql & vbCrLf & "FROM"
            xSql = xSql & vbCrLf & "		T_NEWS"
            xSql = xSql & vbCrLf & "WHERE"
            xSql = xSql & vbCrLf & "        T_NEWS.DEL_FLG = 0"
            xSql = xSql & vbCrLf & "AND		T_NEWS.LINK_NAME     = @NEWS"

            xSql = Replace(xSql, "@NEWS", ToSqlStr(pNews, SqlDataType.DataType_String))

            ds = dataAccess.GetDBDataset(xSql)

            Return ds

        Catch ex As Exception
            Throw ex
        End Try
    End Function

#End Region

End Class